﻿using MediatR;
using Production_Get.API.Infrastructures.Interfaces;
using Return.Enum;
using THE_WIND_RISES.Common.Domans.Produce.Supplier;
using THE_WIND_RISES.Common.Dtos;

namespace Production_Get.API.Application.Commands.Supplier
{
    public class BanksShowHandler : IRequestHandler<BanksShowCommand, THE_WIND_RISES.Common.Dtos.Result>
    {
        /// <summary>
        ///银行信息
        /// </summary>
        private readonly IBaseRepositoryGet<Banks> BanksRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="BanksRepository"></param>
        public BanksShowHandler(IBaseRepositoryGet<Banks> BanksRepository)
        {
            this.BanksRepository = BanksRepository;
        }
        public async Task<Result> Handle(BanksShowCommand request, CancellationToken cancellationToken)
        {
            var result = new THE_WIND_RISES.Common.Dtos.Result() { Code = (int)CommonErrorCodes.Search };

            try
            {
                string sql = $"select * from Banks where SuppliersId={request.SuppliersId} and IsDelete=0";

                var list = BanksRepository.GetAll(sql, default);
                if (list != null)
                {
                    result.Code = (int)CommonErrorCodes.Success;
                    result.Data = list;
                    result.Msg = "显示成功";
                }
                else
                {
                    result.Msg = "显示失败";
                }
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
